import Vue from 'vue';
import Router from 'vue-router';
import Live from '@/views/Live/Index';
import Channel from '@/views/Channel/Index';
import Home from '@/views/Home/Index';
import Index from '@/views/Index/Index';
Vue.use(Router);

const router = new Router({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      name: 'index',
      component: Index
    },
    {
      path: '/home',
      name: 'home',
      component: Home
    },
    {
      path: '/index',
      name: 'index',
      component: Index
    },
    {
      path: '/research',
      name: 'research',
      component: () => import(/* webpackChunkName: "about" */ '@/views/Index/SearchPage')
    },
    // 直播
    {
      path: '/live/:id',
      name: 'live',
      component: Live
    },
    // 直播
    {
      path: '/demo',
      name: 'demo',
      component: () => import(/* webpackChunkName: "about" */ '@/views/Live/Demo')
    },
    {
      path: '/channel',
      name: 'channel',
      component: Channel
    },
    {
      path: '/user',
      name: 'user',
      component: () => import(/* webpackChunkName: "about" */ '@/views/User/Index')
    },
    // {
    //   path: '/search',
    //   name: 'search',
    //   // route level code-splitting
    //   // this generates a separate chunk (about.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import(/* webpackChunkName: "about" */ '@/views/Search.vue')
    // },
    {
      path: '/album',
      name: 'album',
      component: () => import('@/views/Album/Index')
    },
    // 个人中心
    {
      path: '/mine',
      name: 'mine',
      component: () => import('@/views/Mine/Index'),
      redirect: '/mine/nav',
      children: [
        {
          path: 'nav',
          name: 'mineNav',
          component: () => import('@/views/Mine/Navigation'),
        },
        {
          path: 'follow',
          name: 'mineFollow',
          component: () => import('@/views/Mine/Follow'),
        },
        {
          path: 'browsed',
          name: 'browsed',
          component: () => import('@/views/Mine/RecentlyBrowsed'),
        }
      ]
    },
    {
      path: '/info',
      name: 'information',
      component: () => import('@/views/Mine/Information'),
    },
    {
      path: '/income',
      component: () => import('@/views/Mine/Income')
    },
    // 商品、商城
    {
      path: '/goods',
      name: 'goods',
      component: () => import('@/views/Goods/Index'),
    },
    {
      path: '/goodscar',
      name: 'goodCar',
      component: () => import('@/views/Goods/GoodsCar'),
    },
    {
      path: '/goodorder',
      name: 'goodOrder',
      component: () => import('@/views/Goods/GoodsOrder'),
    },
    {
      path: '/gooddetail',
      name: 'goodDetail',
      component: () => import('@/views/Goods/GoodDetail'),
    },
    {
      path: '/history',
      name: 'history',
      component: () => import('@/views/History/Index')
    },
    {
      path: '/redPacket',
      name: 'redPacket',
      component: () => import('@/views/RedPacket/Index')
    },
    {
      path: '/redDetail',
      name: 'redDetail',
      component: () => import('@/views/RedPacket/Detail')
    },
    {
      path: '/redMine',
      name: 'redMine',
      component: () => import('@/views/RedPacket/Mine')
    },
    {
      path: '/piecing',
      name: 'piecing',
      component: () => import('@/views/Piclive/Piecing')
    },
    {
      path: '/video',
      name: 'video',
      component: () => import('@/views/Video/Index')
    },
    {
      path: '/playing',
      name: 'playing',
      component: () => import('@/views/Video/Playing')
    },
    {
      path: '/invitation',
      name: 'invitation',
      component: ()=>import('@/views/Invitation/Index')
    },
    {
      path: '/auction',
      name: 'auction',
      component: ()=>import('@/views/Auction/Index')
    },
    {
      path: '/guide',
      name: 'guide',
      component: ()=>import('@/views/Live/Guide')
    },
    {
      path: '/advert',
      name: 'advert',
      component: ()=>import('@/views/Index/Advert')
    } 
  ]
});


router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next()
});

export default router;
